<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateCouponsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('coupons', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 50);
            $table->integer('money')->default(0);
            $table->decimal('mini_consumption')->default(0); //最低消费
            $table->integer('total')->default(0);    // 发行量
            $table->integer('sent_num')->default(0); // 已领取
            $table->integer('used_num')->default(0); // 已领取

            $table->string('send_type', 20)->default('RECEIVE_FREE'); // 发放类型 LUCK_DRAW
            $table->timestamp('start_send_at')->nullable();
            $table->timestamp('end_send_at')->nullable();

            $table->string('time_type')->default('FIXED');  // 时间类型，FIXED:指定起始时间，SCOPE:领取之日起多少天有效
            $table->integer('time_scope')->default(0);       // 时间范围，单位天
            $table->timestamp('start_use_at')->nullable();
            $table->timestamp('end_use_at')->nullable();

            $table->string('use_scope', 20)->default('ALL');  // 使用范围
            $table->string('use_scope_id')->nullable();             //使用范围id json
            $table->tinyInteger('status')->default(1);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('coupons');
    }
}
